package com.cskaoyan.mall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.product.converter.dto.TrademarkConverter;

import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.dto.TrademarkListDTO;
import com.cskaoyan.mall.product.mapper.TrademarkMapper;
import com.cskaoyan.mall.product.model.Trademark;
import com.cskaoyan.mall.product.query.TrademarkParam;
import com.cskaoyan.mall.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author Macro_Ray
 * @since 2024/6/7 下午4:33
 */
@Service
public class TrademarkServiceImpl implements TrademarkService {

    @Autowired
    TrademarkConverter trademarkConverter;
    @Autowired
    TrademarkMapper trademarkMapper;

    @Override
    public TrademarkListDTO getTrademarkList(Page<Trademark> pageParam) {
        LambdaQueryWrapper<Trademark> trademarkLambdaQueryWrapper = new LambdaQueryWrapper<>();
        trademarkLambdaQueryWrapper.orderByAsc(Trademark::getId);
        // IPage<Trademark> 是用于表示带有分页信息的查询结果的对象，其中包含了分页信息以及查询到的商标数据列表
        Page<Trademark> trademarkPage = trademarkMapper.selectPage(pageParam, trademarkLambdaQueryWrapper);
        return trademarkConverter.tradeMarkListPO2DTO(trademarkPage);
    }

    @Override
    public void saveTrademark(Trademark trademark) {
        trademarkMapper.insert(trademark);
    }

    @Override
    public TrademarkDTO getTrademarkById(Long id) {
        Trademark trademark = trademarkMapper.selectById(id);
        return trademarkConverter.trademarkPO2DTO(trademark);
    }

    @Override
    public void updateTrademark(TrademarkParam trademarkParm) {
        Trademark trademark = trademarkConverter.trademarkParam2Trademark(trademarkParm);
        // todo updateById的参数不应该是两个吗
        trademarkMapper.updateById(trademark);
    }

    @Override
    public void removeTrademarkById(Long id) {
        trademarkMapper.deleteById(id);
    }
}
